package com.cat.dynamicPlanning;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-number-of-texts/
 * @create 2025/8/27 09:01
 * @since JDK17
 */

public class Solution07 {
    static int N = ((int) (1e9 + 7));
    static long[] dp = new long[100001];
    static int[] h = new int[]{0, 0, 3, 3, 3, 3, 3, 4, 3, 4};

    public int countTexts(String pressedKeys) {
        char[] s = pressedKeys.toCharArray();
        Arrays.fill(dp, 0, s.length, 0);
        dp[s.length] = 1;
        for (int i = s.length - 1, j; i >= 0; i--) {
            j = i + 1;
            while (j < s.length && j - i + 1 < h[s[i] - '0'] && s[i] == s[j]) {
                dp[i] += dp[j++];
            }
            dp[i] += dp[j];
            dp[i] %= N;
        }

        return ((int) dp[0]);
    }
}
